<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>01 - 输入法选择,滑动换颜色</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        .box {
            width: 100px;
            margin: 50px auto;
        }

        ul {
            margin-top: 5px;
            display: none;
        }

        li {
            /* line-height: 55px; */
            width: 45px;
            text-align: center;
            border: 1px solid #000;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="button" value="输入法" id="importBtn">
        <ul id="ul">
            <li>简写</li>
            <li>拼音</li>
            <li id="closeBtn">关闭</li>
        </ul>
    </div>
</body>
<script>
    // 1.首先获取所需要的节点
    var importBtn = document.getElementById('importBtn')
    console.log(importBtn);
    var ul = document.getElementById('ul')
    var li = document.getElementsByTagName('li')
    var closeBtn = document.getElementById('closeBtn')

    // 2.点击 输入 按钮 出现 ul
    importBtn.onclick = function () {
        // 3.判断一下，如果 按钮不是‘显示’状态，他现在就是隐藏，就让他点击显示
        if (this.importBtn != 'block') {
            ul.style.display = 'block'
        }
    }

    // 4.滑动到li,出现颜色
    for (var i = 0; i < li.length; i++) {
        // 鼠标经过触发事件
        li[i].onmouseover = function () {
            this.style.background = 'pink'
            this.style.color = '#fff'
        }
        // 鼠标离开触发事件
        li[i].onmouseout = function () {
            this.style.background = ''
            this.style.color = ''
        }
    }

    // 5. 点击关闭 隐藏 ul
    closeBtn.onclick = function () {
        ul.style.display = 'none'
    }

</script>

</html>